<?php
// +----------------------------------------------------------------------
// | When work is a pleasure, life is a joy!
// +----------------------------------------------------------------------
// | User: ShouKun Liu  |  Email:24147287@qq.com  | Time:2016/12/11 13:41
// +----------------------------------------------------------------------
// | TITLE: this to do?
// +----------------------------------------------------------------------
namespace Common\Model;

use Think\Model;


class OrderModel extends Model
{
    const IS_DELETE = 1;
    const NOT_DELETE = 0;

    const ADD_STATUS = 1;//添加
    const  ACTIVATE_STATUS = 2;//激活
    const  QUERY_STATUS = 3;//完成
    const  CLOSE_STATUS = 4;//关闭
    const  OTHER_STATUS = 5;//其他
    const  SET_STATUS = 6;//已设置
    const  ACCEPT_STATUS = 7;//已设置


//CREATE TABLE `lwt_order` (
//`id` int(11) NOT NULL AUTO_INCREMENT,
//`source` varchar(255) DEFAULT '' COMMENT '来源',
//`game_user` varchar(255) DEFAULT '' COMMENT '游戏账号',
//`mobile` varchar(255) DEFAULT '' COMMENT '手机',
//`order_no` varchar(20) DEFAULT '' COMMENT '订单号',
//`create_date` datetime DEFAULT NULL COMMENT '创建时间',
//`dispose_date` datetime DEFAULT NULL COMMENT '处理时间',
//`dispose_user` varchar(255) DEFAULT NULL COMMENT '处理人',
//`status` int(1) DEFAULT '0' COMMENT '状态',
//`is_del` tinyint(1) DEFAULT '0' COMMENT '是否删除',
//PRIMARY KEY (`id`)
//) ENGINE=MyISAM DEFAULT CHARSET=utf8;
    /**
     * 生成订单号
     * @return string
     */
    public static function buildOrderNo()
    {
        return date('YmdHis') . rand(1000, 9999);
    }

    /**
     * 售后单
     * @return array
     */
    public static function afterSaleList()
    {
        return array(
            1=>'是',
            2=>'否'
        );


    }
    /**
     * 状态列表
     * @return array
     *
     */
    public static function statusList()
    {
        return array(
            self::ADD_STATUS => array('title' => '等待中', 'class' => 'danger'),
            self::ACTIVATE_STATUS => array('title' => '激活中', 'class' => 'warning'),
            self::QUERY_STATUS => array('title' => '已完成', 'class' => 'success'),
            self::CLOSE_STATUS => array('title' => '关闭', 'class' => ''),
            self::OTHER_STATUS => array('title' => '其他', 'class' => 'inverse'),
            self::SET_STATUS => array('title' => '已设置', 'class' => 'inverse'),
            self::ACCEPT_STATUS => array('title' => '已接受', 'class' => 'inverse'),
        );


    }

    /**
     * 更新订单状态
     * @param $id
     * @param $status
     * @param $dispose_user
     * @param $userField
     * @return bool
     */
    public function changeOrderStatus($id, $status, $dispose_user,$userField)
    {

        if (!in_array($status, array_keys(self::statusList()))) $status = self::OTHER_STATUS;
        if (empty($dispose_user)) return false;
        $val['status'] = $status;
        $val['dispose_date'] = date('Y-m-d H:i:s');
        $val[$userField] = $dispose_user;
        return $this->where(array('id' => $id))->save($val);

    }


}